<template>
	<scroll-view scroll-y="true" class="swiper-scroll">
		<view class="content">
			<!-- 轮播图 -->
			<swiper class="swiper-box" :circular="true" autoplay :interval="3000" :duration="3000" 
				:indicator-dots="false">
				<swiper-item v-for="(item,index) in slide">
					<view class="swiper-item1" @click="openwv(item.slide_pic)">
						<image :src="item.slide_pic" mode="widthFix" :lazy-load="true"></image>
					</view>
				</swiper-item>
				<swiper-item>
					<view class="swiper-item1" @click="openwv(slide1.slide_pic)">
						<image :src="slide1.slide_pic" mode="widthFix" :lazy-load="true"></image>
					</view>
				</swiper-item>
			</swiper>
			<!-- 热门主播 -->
			<view class="remen_title">
				热门主播
			</view>
			<view class="remen_list">
				<view class="remen_item" v-for="(item, index) in list1" :key="index" @click="room(item)">
					<view class="rm_bg">
						<image :src="item.thumb" mode=""></image>
					</view>
					<view class="rm_bq">
						<image src="/static/image/hot1.png" mode=""></image>
						{{item.live_label}}
					</view>
					<view class="bottom">
						<view class="zbname">
							<view class="name">{{item.user_nicename}}</view>
							<view class="hot">
								<image src="../../static/image/hot.png" mode=""></image>
								<span>{{item.nums}}</span>
							</view>
						</view>
					</view>
				</view>
			</view>
			<!-- 公告 -->
			<view class="gonggao">
				<view class="gg_img">
					<image src="../../static/image/gonggao.png" mode=""></image>
				</view>
				<view class="scroll-text-container">
					<view class="scroll-text">{{ announcementText }}</view>
				</view>
				<!-- <marquee behavior="scroll" direction="left" scrollamount="2">
    				{{ announcementText }}
    			</marquee> -->
			</view>
			<!-- 普通主播 -->
			<view class="remen_list">
				<view class="remen_item" v-for="(item, index) in list2" :key="index" @click="room(item)">
					<view class="rm_bg">
						<image :src="item.thumb" mode=""></image>
					</view>
					<view class="rm_bq">
						<image src="/static/image/hot1.png" mode=""></image>
						{{item.live_label}}
					</view>
					<view class="bottom">
						<view class="zbname">
							<view class="name">{{item.user_nicename}}</view>
							<view class="hot">
								<image src="../../static/image/hot.png" mode=""></image>
								<span>{{item.nums}}</span>
							</view>
						</view>
					</view>
				</view>
			</view>
			<view class="gebanlive">隔板</view>
		</view>

	</scroll-view>
</template>

<script>
	export default {
		onPageScroll(e) {
			console.log(e)
			// this.$set(this.scrollPositions, this.currentTabComponent, e.scrollTop);
		},
		mounted() {
			// this.startScrolling();
		},
		props: {
			announcementText: {
				type: String,
				default: ''
			},
			slide: {
				type: Array,
				default: () => {
					return {}
				}
			},
			slide1: {
				default: () => {
					return {}
				}
			}, 
			list1: {
				type: Array,
				default: () => { 
					return {}
				}
			},
			list2: {
				type: Array,
				default: () => {
					return {}
				}
			},
		},
		watch: {
		    announcementText: function(newData, oldData) {
			 setTimeout(() => {
			     this.startScrolling();
			   }, 100);
		    },
		  },
		data() {
			return {
				list: [{}, {}, {}, {}],
			};
		},
		methods: {
			// 内部打开
			openwv(src) {
				var url = '/pages/index/index';
				uni.setStorageSync('src',src);
				uni.redirectTo({
					// url: '/pages/index/webview?backtype=1&url=' + url + '&src=' + src,
					url: '/pages/index/webview?backtype=1&url=' + url,
				})
			},
			room(item) {
				var token = '';
				var uid = 0;
				if(uni.getStorageSync('token')){
					token = uni.getStorageSync('token');
					uid = uni.getStorageSync('uid');
				}
				this.$api.sendRequest({
					data:{
						service:'Live.checkLive',
						uid:uid,
						token:token,
						liveuid:item.uid,
						stream:item.stream,
						device:uni.getSystemInfoSync()['deviceId'],
					},
					success: res => {
						if(res.data.code == 0){
							var param = res.data.info[0];
							uni.redirectTo({
								url: "/pages/index/room?item="+JSON.stringify(item),
							})
						}else{
							var msg = res.msg == '' ? res.data.msg : res.msg;
							uni.showToast({
								icon: "none",
								title: msg,
							});
						}
					}
				});
				
			},
			// 滚动公告
			startScrolling() {
				const container = document.querySelector(".scroll-text-container");
				const text = document.querySelector(".scroll-text");
				const containerWidth = container.offsetWidth;
				const textWidth = text.offsetWidth;
				if (textWidth > containerWidth) {
					let currentPosition = 0;
					setInterval(() => {
						currentPosition -= 1;
						if (currentPosition < -textWidth) {
							currentPosition = containerWidth;
						}
						text.style.transform = `translateX(${currentPosition}px)`;
					}, 40);
				}
			}
		}
	};
</script>

<style lang="scss">
	// 隔板
	.gebanlive {
		color: #FFFFFF;
		height: 400rpx;
	}

	.content {
		width: 750rpx;
		height: 100vh;
		// min-height: 100%;
		// height: 100vh;
		padding: 20rpx;
		// margin-top: 150upx;
		box-sizing: border-box;
		font-size: 18px;
	}

	.swiper-box {
		// margin-top: 80rpx;
		width: 100%;
		/* position: relative; */
		text-align: center;
		border-radius: 10rpx;
		overflow: hidden;
		height: 220rpx;

		.swiper-item1 {
			width: 100%;
			height: 280rpx;

			image {

				width: 100%;
				height: 100%;
				border-radius: 10rpx;
				overflow: hidden;
			}
		}
	}

	// 滚动公告
	.gonggao {
		width: 100%;
		padding: 20rpx 0;
		overflow: hidden;
		background-image: linear-gradient(270deg,
				rgba(130, 207, 255, 1) 0,
				rgba(197, 157, 252, 1) 100%);
		border-radius: 10rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		margin-top: 10rpx;
		margin-bottom: 20rpx;

		.gg_img {
			width: 50rpx;
			height: 50rpx;
			margin-left: 20rpx;

			image {
				width: 100%;
				height: 100%;
			}
		}

		.scroll-text-container {
			width: 100%;
			overflow: hidden;

			.scroll-text {
				color: #FFFFFF;
				white-space: nowrap;
				display: inline-block;
				font-size: 32rpx;
			}
		}


		marquee {
			width: 100%;
			white-space: nowrap;
			font-size: 32rpx;
			color: #ffffff;
		}
	}

	.remen_list {
		display: flex;
		flex-wrap: wrap;
		// justify-content: space-around;
		justify-content: start;

		.remen_item {
			width: 342rpx;
			height: 342rpx;
			padding: 6rpx;
			// margin-bottom: 10rpx;
			border-radius: 8rpx;
			overflow: hidden;
			.rm_bg {
				width: 342rpx;
				height: 342rpx;
				position: absolute;
				border-radius: 8rpx;
				overflow: hidden;

				image {
					width: 100%;
					height: 100%;
				}
			}

			.rm_bq {
				width: 120rpx;
				height: 38rpx;
				position: relative;
				top: 0rpx;
				// background-color: red;
				background-image: linear-gradient(
				270deg
				, #82cfff 0, #c59dfc 100%);
				color: #FFFFFF;
				font-size: 24rpx;
				display: flex;
				align-items: center;
				justify-content: center;
				image {
					width: 30rpx;
					height: 30rpx;
				}
			}

			.bottom {
				position: relative;
				bottom: -250rpx;
				padding: 10rpx;

				.talk {
					border: 2rpx solid #b3b0b0;
					color: #b3b0b0;
					border-radius: 40rpx;
					padding: 2rpx 6rpx;
					font-size: 18rpx;
					display: inline-block;
				}

				.title {
					color: #FFFFFF;
					font-size: 28rpx;
					margin-top: 6rpx;
				}

				.zbname {
					display: flex;
					justify-content: space-between;
					margin-top: 6rpx;

					.name {
						color: #FFFFFF;
						font-size: 24rpx;
					}

					.hot {
						display: flex;
						align-items: center;

						image {
							width: 40rpx;
							height: 40rpx;
						}

						span {
							color: #FFFFFF;
							font-size: 24rpx;
						}
					}
				}
			}
		}
	}

	.remen_title {
		font-size: 40rpx;
		color: #1D1D1D;
		font-weight: bold;
		margin: 30rpx 0;
	}
</style>